<?php
require_once '../utils/common.php';
require_once '../Config.php';
$conn = mysql_connect ( host, username, password );
if (! $conn) {
	die ( "连接失败" . mysql_error () );
}
mysql_select_db ( db, $conn );
$flag = $_REQUEST['flag'];
if($flag == "add"){
	$icon = upload("icon");
	$name = $_REQUEST['name'];
	$link = $_REQUEST['link'];
	$type = $_REQUEST['type'];
	$isPhone = $_REQUEST['isPhone'];
	$sql = "set names utf8";
	mysql_query($sql);
	$sql = "insert into j_tab_model(icon, name, link, type, isPhone) values ('".$icon."','".$name."','".$link."',".$type.",".$isPhone.")";
	mysql_query($sql);
	mysql_close($conn);
	echo "<script>alert('添加成功!');self.location='ModelManager.php?type=$type';</script>";
}else if($flag == 'del'){
	$id = $_REQUEST['id'];
	$sql = "delete from j_tab_model where id=".$id;
	mysql_query($sql);
	mysql_close($conn);
	echo "<script language=\"JavaScript\">\r\n";
	echo " alert(\"删除成功\");\r\n";
	echo " history.back();\r\n";
	echo "</script>";
	exit;
}else if($flag == 'update'){
	$id = $_REQUEST['id'];
	$icon = upload("icon");
	$name = $_REQUEST['name'];
	$link = $_REQUEST['link'];
	$type = $_REQUEST['type'];
	$isPhone = $_POST['isPhone'];
	$sql = "set names utf8";
	mysql_query($sql);
	if($icon == ""){
		$sql = "update j_tab_model set name='".$name."',link='".$link."',type=".$type.",isPhone=".$isPhone." where id=".$id;
	}else{
		$sql = "update j_tab_model set icon='".$icon."',name='".$name."',link='".$link."',type=".$type.",isPhone=".$isPhone." where id=".$id;
	}
	
	mysql_query($sql);
	mysql_close($conn);
	echo "<script>alert('修改成功!');self.location='ModelManager.php?type=$type';</script>";
}



?>